package io.github.shenbinglife.springboot2.layui.admin.entity;

import io.github.shenbinglife.springboot2.layui.common.model.BaseEntity;
import io.github.shenbinglife.springboot2.layui.common.model.TreeNode;
import io.github.shenbinglife.springboot2.layui.common.utils.JpaConverterMapJson;

import javax.persistence.Column;
import javax.persistence.Convert;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Map;

/**
 * Menu
 *
 * @author shenbing
 * @date 2021/4/12 21:29
 */
@Entity
@Table(name = "tbl_sys_menu")
public class Menu extends BaseEntity {
    @Column(name = "parent_id")
    private Long parentId;
    private String name;
    private String link;
    private Boolean leaf;
    private String icon;
    private Integer ordered;
    private String description;

    @Convert(converter = JpaConverterMapJson.class)
    @Column(columnDefinition = "TEXT")
    private Map<String, Object> extraConfig;

    public Long getParentId() {
        return parentId;
    }

    public void setParentId(Long parentId) {
        this.parentId = parentId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getLink() {
        return link;
    }

    public void setLink(String link) {
        this.link = link;
    }

    public Boolean getLeaf() {
        return leaf;
    }

    public void setLeaf(Boolean leaf) {
        this.leaf = leaf;
    }

    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = icon;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Integer getOrdered() {
        return ordered;
    }

    public void setOrdered(Integer ordered) {
        this.ordered = ordered;
    }

    public Map<String, Object> getExtraConfig() {
        return extraConfig;
    }

    public void setExtraConfig(Map<String, Object> extraConfig) {
        this.extraConfig = extraConfig;
    }

    public TreeNode<Long> toTreeNode(Long parentId) {
        TreeNode<Long> tree = new TreeNode<>();
        tree.setId(this.getId());
        tree.setParentId(parentId);
        tree.setName(this.name);
        tree.setIcon(this.icon);
        tree.setAttributes(this.extraConfig);
        tree.setLink(this.link);
        tree.setOrdered(this.ordered);
        tree.setLeaf(this.leaf);
        return tree;
    }
}
